@extends('admin._layouts.default')

@section('main')

{{--<script type="text/javascript" src="http://vbafang.com/@system/js/jquery.js"></script>--}}
<script type="text/javascript" src="http://libo.wechat28.com/style/admin/js/jquery.js"></script>

<script src="http://api.map.baidu.com/api?v=1.5&ak=1b0ace7dde0245f796844a06fb112734"></script>
{{ Form::model($area, array('method' => 'put', 'route' => array('admin.areas.update', $area->id),'files'=>true,'id'=>'areas','class'=>'bs-docs-example form-horizontal')) }}
	<input type="hidden" value = "{{ $area->id }}" name="D1pFYl4A" id="lbsid" />
	<input type="hidden" value = "{{ $data['y'] }}" name="D1pFYl0A" id="lbsjd" />
	<input type="hidden" value = "{{ $data['x'] }}" name="D1pFYkAA" id="lbswd" />
	<input type="hidden" value = "{{ $data['set'] }}" id="ifset" />
    <div class="control-group">

	</div>
		<div class="control-group"></div>



		<div class="control-group">
			<label class="control-label span4" for="address">地址：&nbsp</label>
			<div class="controls span8">
			<input type="text"   value="{{ $area->name }}" name="D1pFYlYAUhEAFkM=" id="lbsaddress" class="span5"/>
							<button id="locate-btn" class="btn btn-primary">定位</button>
				<span class="maroon">*</span><br>
				<span class="help-inline">输入地址后，点击“自动定位”按钮可以在地图上定位。</span><br>
				<span class="help-inline">（如果输入地址后无法定位，请在地图上直接点击选择地点）</span>
			</div>
		</div>
		<div id="map" style="width: 600px;height: 300px;margin-left: 100px;"></div>
 		<div class="control-group">

			<div class="controls offset4 span8">
               @if($area->cover)<img src="http://aebo.qiniudn.com/{{ $area->cover }}-smile"> @endif
          </div>
 		</div>
	  	<div class="control-group">
			<label class="control-label span4" for="address">照片：&nbsp</label>
			<div class="controls span8">
               @if($area->cover)
			  	<input type="file" value="上传图片" name="cover">
               @else
			  	<input type="file" value="上传图片" name="cover" required>
               @endif
			  </div>
	  	</div>
 		<div class="control-group">

			<div class="controls offset4 span8">
                  <button type="submit" class="btn btn-primary"><i class="fa fa-cog fa-spin"></i> 保存</button>
          </div>
 		</div>
	{{ Form::close(); }}

<script type="text/javascript">
//是否从未保存过定位信息，如果从未保存过，并且有填地址信息，那么进入页面后自动定位
var located = true;
//定位坐标
var destPoint = new BMap.Point($('#lbsjd').val(),$('#lbswd').val());
$(function(){

	/**开始处理百度地图**/
	var map = new BMap.Map("map");
	map.centerAndZoom(new BMap.Point(destPoint.lng, destPoint.lat), 12);//初始化地图
	map.enableScrollWheelZoom();
	map.addControl(new BMap.NavigationControl());
	var marker = new BMap.Marker(destPoint);
	map.addOverlay(marker);//添加标注

	map.addEventListener("click", function(e){
		if(confirm("确认选择这个位置？")){
			destPoint = e.point;
			$('#lbsjd').val(destPoint.lng);
			$('#lbswd').val(destPoint.lat);
			map.clearOverlays();
			var marker1 = new BMap.Marker(destPoint);  // 创建标注
			map.addOverlay(marker1);
		}
	});

    search();


	var myValue;

	var local;
	function setPlace(){
	    map.clearOverlays();    //清除地图上所有覆盖物
	    local = new BMap.LocalSearch(map, { //智能搜索
	      renderOptions:{ map: map}
	    });
	    located = true;
	    local.setMarkersSetCallback(callback);
	    local.search(myValue);
	}

	function addEventListener(marker){
		marker.addEventListener("click", function(data){
			destPoint = data.target.getPosition(0);
		});
	}
	function callback(posi){
		$("#locate-btn").removeAttr("disabled");
		for(var i=0;i<posi.length;i++){
			if(i==0){
				destPoint = posi[0].point;
			}
			posi[i].marker.addEventListener("click", function(data){
				destPoint = data.target.getPosition(0);
			});
		}
	}

    function search(){
        var set = $("#ifset").val();
        if(set == 0){
            $("#locate-btn").attr("disabled","disabled");
            local = new BMap.LocalSearch(map, { //智能搜索
                renderOptions:{ map: map}
            });
            located = true;
            local.setMarkersSetCallback(callback);
            local.search($("#lbsaddress").val());
            return false;
        }
    }


	$("#lbsl_xianqu").change(function(){
		$("#locate-btn").attr("disabled","disabled");
		local = new BMap.LocalSearch(map, { //智能搜索
			renderOptions:{ map: map}
		});
		located = true;
		local.setMarkersSetCallback(callback);
		local.search($("#lbsl_xianqu").find('option:selected').text());
		return false;
	});
	$("#lbsl_shi").change(function(){
		$("#locate-btn").attr("disabled","disabled");
		local = new BMap.LocalSearch(map, { //智能搜索
			renderOptions:{ map: map}
		});
		located = true;
		local.setMarkersSetCallback(callback);
		local.search($("#lbsl_shi").find('option:selected').text());
		return false;
	});
	$("#locate-btn").click(function(){
		if($("#lbsaddress").val() == ""){
			alert("请输入门店地址！");
			return ;
		}
		$("#locate-btn").attr("disabled","disabled");
		local = new BMap.LocalSearch(map, { //智能搜索
			renderOptions:{ map: map}
		});
		located = true;
		local.setMarkersSetCallback(callback);
		local.search($("#lbsaddress").val());
		return false;
	});
	/**结束百度地图处理**/
	$("#close-btn").click(function(){
    	if(confirm("你确定要停用LBS功能？")){
    		var submitData = {
    			"action":"close",
    			"wuid":19979,
    			"lid":null
    		};
    		$.post("/admin/lbsinfo",submitData,function(data){
    			if(data.success){
    				window.location.reload();
    			} else{
    				alert("停用失败");
    			}
    		},"json");
    	}
    });

});
</script>
<br/><br/><br/>



@stop




@section('script')



<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/full-calendar/fullcalendar.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/jquery.peity.min.js') }}"></script>
<script type="text/javascript" language="javascript" src="{{ URL::asset('ad/js/plugins/datatables/js/jquery.dataTables.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/flot/jquery.flot.js') }}"></script>
<script src="{{ URL::asset('ad/js/plugins/justGage.1.0.1/resources/js/raphael.2.1.0.min.js') }}"></script>
<script src="{{ URL::asset('ad/js/plugins/justGage.1.0.1/resources/js/justgage.1.0.1.min.js') }}"></script>
<script src="{{ URL::asset('ad/js/scripts.js') }}"></script>


    <script type="text/javascript" charset="utf-8">
    // Datatables
    $(document).ready(function() {
      var dontSort = [];
                $('#datatable_city thead th').each( function () {
                    if ( $(this).hasClass( 'no_sort' )) {
                        dontSort.push( { "bSortable": false } );
                    } else {
                        dontSort.push( null );
                    }
      } );
      $('#datatable_city').dataTable( {
        "sDom": "<'row table_top_bar'<'row-fluid'>'<'to_hide_phone'>'f'<'>r>t<'row'>",
         "sDom": "<'row table_top_bar'<'row-fluid'<'to_hide_phone' f>>><'row'>",
         "aaSorting": [[ 1, "asc" ]],
        "bPaginate": false,
        "bJQueryUI": false,
        "aoColumns": dontSort

      } );
      $.extend( $.fn.dataTableExt.oStdClasses, {
        "s`": "dataTables_wrapper form-inline"
      } );
    } );
    </script>
    <script>

    function set_delete(id){
        $('#delete_id').val(id);
    }
    function delete_it(){
        $('#area_form').submit();
    }
    </script>
@stop
